/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package logic;

import dao.EmployeeDaoImpl;
import dto.DepartmentDto;
import dto.EmployeeDto;
import dto.RoleDto;
import java.util.ArrayList;

/**
 *
 * @author ADMIN
 */
public class EmployeeLogicImpl {

    private EmployeeDaoImpl empDao;
    public EmployeeLogicImpl() {
        empDao = new EmployeeDaoImpl();
    }
    
    public EmployeeDto getEmployeeByID(int empID){
        return empDao.getEmployeeByID(empID);
    }
    public EmployeeDto getUser(String user, String password) {
        return empDao.getEmployeeByUserName(user, password);
    }
    public DepartmentDto getDeparment(int Id){
        return empDao.getDepartmentByID(Id);
    }
    public DepartmentDto getDepartmentByName(String deptName){
        return empDao.getDepartmentByName(deptName);
    }
    public RoleDto getRole (int roleID){
        return empDao.getRoleByID(roleID);
    }
    
    public RoleDto getRoleByName (String roleName){
        return empDao.getRoleByName(roleName);
    }
    
    public ArrayList<EmployeeDto> getListEmployee(String name, int deptID){
        DepartmentDto deptDto;
        RoleDto roleDto;
        EmployeeDto manager;
        ArrayList<EmployeeDto> list = empDao.getListEmployee(name, deptID);
        for (int i = 0; i < list.size(); i++) {
            deptDto = getDeparment(list.get(i).getDeptID());
            roleDto = getRole(list.get(i).getRoleID());
            if(list.get(i).getManagerID() == 0){
                list.get(i).setManagerName("No Managerment");
            }else{
                manager = getEmployeeByID(list.get(i).getManagerID());
                list.get(i).setManagerName(manager.getEmployeeName());
            }
            list.get(i).setDepartmentName(deptDto.getDepartmentName());
            list.get(i).setRoleName(roleDto.getRoleName());
        }
        return list;
    }
    
     public ArrayList<RoleDto> getListRole(){
         return empDao.getListRole();
     }
     
     public ArrayList<DepartmentDto> getListDepartment(){
         return empDao.getListDepartment();
     }
     
     public ArrayList<EmployeeDto> getListManager(){
         return empDao.getListManager();
     }
     
     public boolean insertEmployee(EmployeeDto dto){
         return empDao.insertEmployee(dto);
     }
}
